#include "mbed.h"
#include "rtos.h"
#include "baidu_mp3_data_mgr.h"
#include "baidu_http_client_log.h"
#include "baidu_mbed_soc_wrapper.h"
#include "baidu_http_client_c.h"
#if defined(TARGET_UNO_91H)
#include "SDMMCFileSystem.h"
#elif defined(TARGET_K64F)
#include "SDFileSystem.h"
#else
#error "Not supported"
#endif
#include "baidu_media_play.h"


/*********************following is a thread to send test cmd to MDM thread***********************************/
#define MDM_CMD_TEST_URL "http://mqtt.org/"
//#define MDM_CMD_TEST_URL "http://yinyueshiting.baidu.com/data2/music/88c35d23074a0f05a86b87492ce9e423/270634780/270634732187200128.mp3?xcode=f80ea9fdf4998048b6f28ebc1a3b5868"
#define MDM_CMD_TEST_FILE_PATH  "/sd/niuliucheenghe-zh.mp3"

static void mdm_cmd_test_send(void *arg);

static RtosTimer *p_g_cmd_timer = NULL;


static void mdm_cmd_test_send(void const *arg) {
    static int counter = 0;

    HCFUNC_ENTER();

    HCLOGI("CMD TEST counter:%d\n", counter);

    if (counter == 0){
        //mdm_send_mp3_url(MDM_CMD_TEST_URL);
    }
    else if (counter == 1){
       mdm_send_mp3_file_path(MDM_CMD_TEST_FILE_PATH);
    }
    else if (counter == 2){
       // mdm_notify_to_stop();
        p_g_cmd_timer->stop();
    }

    counter++;
    
    HCFUNC_LEAVE();
}


void mdm_cmd_test_thread(void const *arg) 
{
    HCFUNC_ENTER();
    
    p_g_cmd_timer = new RtosTimer(mdm_cmd_test_send, osTimerPeriodic, NULL);

    p_g_cmd_timer->start(1000);

    
    Thread::wait(osWaitForever);

    HCFUNC_LEAVE();
}
/*************************UP is a thread to send test cmd to MDM thread***********************************/



int main()
{  

    HCLOGI("Entry mp3 data mgr main!\n");


    Thread mdm_thread(mp3_data_mgr_thread, NULL, osPriorityNormal, MDM_THREAD_STACK_SIZE);
    Thread mdm_cmd_thread(mdm_cmd_test_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
    Thread thread(media_play_thread, NULL, osPriorityNormal, MDM_THREAD_STACK_SIZE);
        
    Thread::wait(osWaitForever);
}
























